package com.example.demo;
import org.springframework.stereotype.Component;

import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-06-13
 * Time: 11:24
 */

@Component
public class Timerdemo {
    private Random random = new Random();

    public void sendRandomNumber() {
        int randomNumber = random.nextInt(100);
        // 在此处编写发送随机数的代码
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                // 在此处编写让随机数失效的代码

            }
        }, 180000); // 180000毫秒即3分钟
    }
}
